<?php
/**
 * Created by PhpStorm.
 * User: apple
 * Date: 2018/11/24
 * Time: 9:40 AM
 */

namespace app\shop\validate;

class Category extends \ShopValidate
{
    protected $rule = [
        'cate_name' => 'require|max:30',
        'parent_id' => 'require|checkExists',
    ];

    protected $message = [
//        'cate_name.require' => '分类名称必须',
//        'cate_name.max' => '分类名称长度不能超过30个字符',
        'parent_id.checkExists' => '指定的父级分类不存在',
    ];

    protected $field = [
        'cate_name' => '分类名称',
        'parent_id' => '父级分类ID',
    ];

    protected $scene = [
        'save' => ['parent_id'],
    ];

    protected function checkExists($cateId)
    {
        if ($cateId === 0) return true;
        return call_user_func([new \app\shop\controller\Category(), 'checkExists'], $cateId);
    }

}